package com.ning.activitys.skysound.adpter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.ning.activitys.skysound.fragment.FindMusicFragment;
import com.ning.activitys.skysound.fragment.MusicPavilionFragment;
import com.ning.activitys.skysound.fragment.MyMusicFrament;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/8.
 */
public class MainAdapter extends FragmentPagerAdapter{

    private List<Fragment> fragments;
    private String titles[] = {"我的音乐","音乐馆","发现音乐"};
    Fragment myMusic;
    Fragment musicPavilion;
    Fragment foundMusic;

    public Fragment getMyMusicFragment(){
        return myMusic;
    }

    public MainAdapter(FragmentManager fm) {
        super(fm);
        fragments = new ArrayList<>();
        myMusic = new MyMusicFrament();
        musicPavilion = new MusicPavilionFragment();
        foundMusic = new FindMusicFragment();

        fragments.add(myMusic);
        fragments.add(musicPavilion);
        fragments.add(foundMusic);
    }

    @Override
    public Fragment getItem(int position) {
        /*
        if (position == 0){
            if (myMusic == null){
                myMusic =  AllFragment.newInstance();
            }
        }else if (position == 1){
            //判断是哪个Fragment
            //跟上面一样,在Fragment 里写一个静态的实例化方法 调用
        }
*/
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }


}
